<template>
    <div class="info_chang_box">
        <div class="info_chang_search">
            <div class="tabs">
                <div class="tabs-label">当前位置：</div>
                <div class="tabs-items">
                    <div @click="$router.push({name: 'home'})" class="tabs-item">首页</div>
                    <div @click="$router.push({name: 'groups'})" class="tabs-item"> > 产品商城</div>
                    <template v-for="item in crumbsList">
                        <div v-if="item.name != ''" @click="routerCuse(item.id)" class="tabs-item"> > {{item.name}}</div>
                    </template>
                </div>
            </div>
            <search-box></search-box>
        </div>
        <div class="product-intro" v-if="!currentGroup.id && productIntro" v-html="productIntro"></div>
        <div v-if="groupList.length > 0" class="group_info" :class="{'group-info-tree': currentGroup.id}">
            <div v-if="currentGroup.id" class="group-tree">
                <div class="tree-title">{{currentGroup.name}}</div>
                <div class="tree-dom">
                    <el-tree accordion :data="groupList" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
                </div>
            </div>
            <div class="group_infos" :class="{col4: currentGroup.id, col5: !currentGroup.id}">
                <div v-if="currentGroup.id" class="current-group-info">
                    <div class="current-group-info-head">
                        <el-image fit="cover" :src="currentGroup.icon" class="current-group-info-icon"></el-image>
                        <div class="current-group-info-name">{{currentGroup.name}}</div>
                    </div>
                    <div class="current-group-info-desc">{{currentGroup.info}}</div>
                </div>
                <div class="group_box">
                    <div class="info_groups" @click="goGroupTwo(items)" v-for="(items) in groupList">
                        <div class="group_img">
                            <img :src="items.cover ? items.cover : items.icon" class="img_box">
                        </div>
                        <div class="group_titles">{{items.name}}</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import {getGroupInfo} from "@/api/apis";
    import SearchBox from "@/components/searchBox";

    export default {
        name: "groupHome",
        components: {SearchBox},
        data() {
            return {
                groupList: [],
                group_id: '',
                crumbsList: [],
                currentGroup: {},
                defaultProps: {
                    children: 'list',
                    label: 'name'
                }
            }
        },
        computed: {
            productIntro() {
                return this.$store.state.productIntro ?? false;
            }
        },
        mounted() {
            if (this.$route.query.group_id) {
                this.group_id = this.$route.query.group_id
            }
            this.GetGroupInfo()
        },
        watch: {
            $route(to, from) {
                if (to.query.group_id != from.query.group_id) {
                    this.group_id = to.query.group_id
                    this.GetGroupInfo()
                }
            }
        },
        methods: {
            openGroupList(e) {
                let obj = this.groupList[e]
                if (obj.list.length > obj.openNum) {
                    obj.openNum = obj.length
                } else {
                    obj.openNum = 5
                }
            },
            openGroupMainList() {
                if (this.emptyChildList.length > this.currentGroup.openNum) {
                    this.currentGroup.openNum = this.emptyChildList.length;
                } else {
                    this.currentGroup.openNum = 5
                }
            },
            routerCuse(e) {
                this.$router.push({name: 'groups', query: {group_id: e}})
            },
            GetGroupInfo() {
                let data = {group_id: this.group_id}
                getGroupInfo(data).then(res => {
                    if (res.data.list.length) {
                        res.data.list.map(item => {
                            item.openNum = 5
                        })
                    }
                    this.groupList = res.data.list;

                    this.crumbsList = res.data.p_info;
                    this.currentGroup = JSON.parse(JSON.stringify(res.data.p_info)).pop();
                    this.$set(this.currentGroup, 'openNum', 5);
                });
            },
            goLastGroup(item, index) {
                if (item.is_end) {
                    this.$router.push({name: 'filterGroups', query: {group_id: item.id}})
                } else {
                    this.openGroupList(index)
                }
            },
            goGroupTwo(e) {
                if (e.is_end) {
                    this.$router.push({name: 'filterGroups', query: {group_id: e.id}})
                } else {
                    this.$router.push({name: 'groups', query: {group_id: e.id}})
                }
            },
            handleNodeClick(data) {
                if (data.list.length <= 0) {
                    this.goGroupTwo(data);
                }
            }
        }
    }
</script>

<style scoped lang="less">
    .info_chang_box {
        margin: 0 auto;
        padding-top: 11px;
        width: 1200px;
        
        .info_chang_search {
            width: 1200px;
            display: flex;
            cursor: pointer;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 33px;
            
            .tabs {
                font-size: 14px;
                font-family: Microsoft YaHei;
                font-weight: 400;
                color: #000000;
                width: calc(100% - 560px);
                display: flex;
                
                .tabs-label {
                    width: 76px;
                }
                
                .tabs-items {
                    width: calc(100% - 76px);
                    display: flex;
                    flex-wrap: wrap;
                    color: #333333;
                    
                    .tabs-item {
                        margin-right: 5px;
                    }
                }
            }
        }
        
        
        .group_info {
            cursor: pointer;
            display: flex;
            
            
            &.group-info-tree {
                justify-content: space-between;
            }
            
            .group_changs {
                display: flex;
                justify-content: space-between;
                align-items: center;
                
                .group_info_content {
                    width: 80%;
                    
                    .group_one_title {
                        display: flex;
                        align-items: center;
                        margin-bottom: 9px;
                        
                        img {
                            width: 30px;
                            height: 28px;
                            margin-right: 12px;
                        }
                        
                        .titles {
                            font-size: 20px;
                            font-family: Microsoft YaHei;
                            font-weight: bold;
                            color: #000000;
                        }
                    }
                    
                    .group_json {
                        font-size: 14px;
                        font-family: Microsoft YaHei;
                        font-weight: 400;
                        color: #9D9D9D;
                        margin-bottom: 28px;
                    }
                }
                
                .more_infos {
                    width: 58px;
                    height: 24px;
                    border: 1px solid #000000;
                    box-sizing: border-box;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    font-size: 12px;
                    text-align: center;
                    line-height: 24px;
                    
                    img {
                        width: 30px;
                        height: 7px;
                    }
                    
                    .select {
                        display: none;
                    }
                    
                    .uncheck {
                        display: block;
                    }
                }
                
                .more_infos:hover {
                    border-color: #B11E24;
                    color: #B11E24;
                    
                    .select {
                        display: block;
                    }
                    
                    .uncheck {
                        display: none;
                    }
                }
            }
            
            .group-tree {
                width: 225px;
                
                .tree-title {
                    background-color: #000000;
                    color: #FFFFFF;
                    font-size: 18px;
                    text-align: center;
                    padding: 15px;
                    border-radius: 10px 10px 0 0;
                }
                
                .tree-dom {
                    .el-tree {
                        background-color: #f7f7f7;
                        padding: 15px;
                        border-radius: 0 0 10px 10px;
                        color: #484747;
                    }
                }
            }
            
            .group_infos {
                &.col4 {
                    width: calc(100% - 245px);
                    
                    .group_box {
                        .info_groups:nth-child(4n) {
                            margin-right: 0;
                        }
                    }
                }
                
                &.col5 {
                    .group_box {
                        .info_groups:nth-child(5n) {
                            margin-right: 0;
                        }
                    }
                }
                
                .current-group-info {
                    margin-bottom: 28px;
                    
                    .current-group-info-head {
                        display: flex;
                        align-items: center;
                        margin-bottom: 9px;
                        
                        .current-group-info-icon {
                            width: 30px;
                            height: 30px;
                            margin-right: 12px;
                        }
                        
                        .current-group-info-name {
                            font-size: 20px;
                            font-family: "Microsoft YaHei";
                            font-weight: bold;
                            color: #000000;
                        }
                    }
                    
                    .current-group-info-desc {
                        font-size: 14px;
                        font-family: "Microsoft YaHei";
                        font-weight: 400;
                        color: #9D9D9D;
                    }
                }
                
                .group_box {
                    display: flex;
                    flex-wrap: wrap;
                    
                    .info_groups {
                        width: 217px;
                        margin-right: 28px;
                        margin-bottom: 28px;
                        
                        .group_img {
                            height: 150px;
                            background: rgba(0, 0, 0, 0);
                            border: 1px solid #E9E9E9;
                            box-sizing: border-box;
                            
                            .img_box {
                                width: 100%;
                                height: 100%;
                                object-fit: cover;
                            }
                        }
                        
                        .group_titles {
                            text-align: center;
                            font-size: 14px;
                            font-family: Microsoft YaHei;
                            font-weight: 400;
                            color: #000000;
                            margin-top: 10px;
                        }
                    }
                    
                    .info_groups:hover .group_img {
                        border-color: #B11E24;
                        transition: all 0.3s linear;
                    }
                    
                    .info_groups:hover .group_titles {
                        color: #B11E24;
                        transition: all 0.3s linear;
                    }
                }
                
            }
        }
    }
</style>
